<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class bannerMainCat_model extends CI_Model
{
    public function __construct()
	{
		parent::__construct();
	}
	  
      function getAllBannerCat($num,$offset)
	  {
          //$this->db->where('status !=',-1);
		  //$this->db->order_by("lastedit","DESC") ;
          $query = $this->db->get('bannermain_cat');
          return $query->result();
      }
      function getNumBannerCat()
	  {
		//$this->db->where('status !=',-1);
		$query = $this->db->get('bannermain_cat');
		return $query->num_rows();
      }
      
	  function getBannerCat($id=0, $num=15, $start=0)
	  { 
			if(!empty($id)) $this->db->where('idBannerCat',$id);
			$query = $this->db->get('bannermain_cat', $num, $start);
			return $query->row();
      }
	  
      function saveUpdateBannerCat()
	  {
          $id = (int)$this->uri->segment(3);
          $lb_name_cat = $this->input->post('lb_name_cat');
		  $ParentID = $this->input->post('ParentID');
		  $images = $this->input->post('images');
		  $cm_banner_cat = $this->input->post('cm_banner_cat');
		  $status  = $this->input->post('status');
		  
          $data = array(
            'subject' => $lb_name_cat,
			'parentID' => $ParentID,
			'images' => $images,
			'cm_baner_cat' => $cm_banner_cat,
            'status'   => $status
          );
          if($id != 0)
		  {
              $this->db->where('idBannerCat',$id);
              if($this->db->update('bannermain_cat',$data)){
                  return true;
              }else{
                  return false;
              }
          }else{

              if($this->db->insert('bannermain_cat',$data)){
                  return true;
              }else{
                  return false;
              }
          }          
      }
      
      // Begin List tour
      function getNum_GalleryCat()
	  {      
          $query = $this->db->get('picture_cat');
          return $query->num_rows();
      }
      //Save tour
      function saveGalleryCat()
	  {
          $id = (int)$this->uri->segment(3);
          $data = array(
            'cd_gallery_cat' => (string)$this->input->post('cd_gallery_cat'),
            'lb_gallery_cat' => (string)$this->input->post('lb_gallery_cat'),
            'cm_gallery_cat' => (string)$this->input->post('cm_gallery_cat'),
            'status' => (int)$this->input->post('status')    
          );
          if($id!=0){
              $this->db->where('id_gallery_cat',$id);
              if($this->db->update('picture_cat',$data)){
                  return true;
              }else{
                  return false;
              }
          }else{
              if($this->db->insert('picture_cat',$data)){
                  return true;
              }else{
                  return false;
              }
          }
      }
	  
      function delbannercat($id)
	  {          
          $this->db->where('idBannerCat',$id);
          if($this->db->delete('bannermain_cat')){
              return true;
          }else{
              return false;
          }
      }
      function getItemCat()
	  {
          $this->db->where('App',0);
          $catid = $this->uri->segment(3);
          $this->db->where('CatID',$catid);
          $query = $this->db->get('contentcat');
          return $query->row();
      }
      
      function get_Parent($CatID)
	  {
          $this->db->where('App',0);
          $this->db->where('imagetour',$CatID);
          return $this->db->get('contentcat')->result();
      }
      
      function getListCat(){
          return $this->db->get('bannermain_cat')->result();
      }   
      
      function deltour($id){
          $this->db->select('tourid, imgtour');
          $this->db->where('App',0);
          $this->db->where('tourid',$id);
          $check = $this->db->get('content')->row();
          if($check){
              if(file_exists('../uploads/tour/'.$check->imgtour)){
                  unlink('../uploads/tour/'.$check->imgtour);
              }
              $this->db->where('tourid',$id);
              if($this->db->delete('content')){
                  return true;
              }else{
                  return false;
              }
          }else{
              return false;
          }
      }
      
      //Update tour
      function getItemGalleryCat(){
          $id = (int)$this->uri->segment(3);
          $this->db->where('id_gallery_cat',$id);
          $query = $this->db->get('picture_cat');
          return $query->row();
      }
  }
?>
